// 0 引入用来发送请求的方法
import { request } from "../../request/index.js";
Page({
    data: {
        // 轮播图数组
        swiperList: [],
        // 导航数组
        catesList: [],
        // 楼层数组
        floorList: [],
    },
    //options(Object)
    onLoad: function(options) {
        // 发送异步请求获取轮播图数据
        // wx.request({
        //     url: 'https://api-hmugo-web.itheima.net/api/public/v1/home/swiperdata',
        //     header: {
        //         'content-type': 'application/json' // 默认值
        //     },
        //     success: (result) => {
        //         // console.log(result);
        //         this.setData({
        //             swiperList: result.data.message
        //         })
        //     }
        // });
        this.getSwiperList()
        this.getCatesList()
        this.getFloorList()
    },
    // 获取轮播图数据
    async getSwiperList() {
        const res = await request({ url: '/home/swiperdata' })
        const swiperList = res.data.message;
        // console.log(swiperList);
        swiperList.forEach(v => {
            v.navigator_url = v.navigator_url.replace('main', "goods_detail")
        });

        this.setData({
            swiperList
        })

    },
    // 获取分类导航数据
    getCatesList() {
        request({ url: '/home/catitems' }).then(result => {
            this.setData({
                catesList: result.data.message
            })
        })
    },
    // 获取楼层数据
    async getFloorList() {
        const res = await request({ url: '/home/floordata' })
        let floorList = res.data.message;
        console.log(floorList);
        floorList.forEach(val => {
            val.product_list.forEach(v => {
                v.navigator_url = v.navigator_url.replace('goods_list', "goods_list/goods_list")
            })
        })


        this.setData({
            floorList
        })

    },


    onReady: function() {

    },
    onShow: function() {

    },
    onHide: function() {

    },
    onUnload: function() {

    },
    onPullDownRefresh: function() {

    },
    onReachBottom: function() {

    },
    onShareAppMessage: function() {

    },
    onPageScroll: function() {

    },
    //item(index,pagePath,text)
    onTabItemTap: function(item) {

    }
});